package zhjb.temp.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import zhjb.temp.db.test.Test;

public class MysqlTest {
	public static void main(String[] args) {
		try {
			Context.registe(Test.class);
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://127.0.0.1:3306/test";
			String uname = "root";
			String pwd = "123456";
			Connection conn = DriverManager.getConnection(url, uname, pwd);
			DaoContext.add(conn);
			Test t = new Test();
			t.setName("name");
			t.setGuid("guid");
			DataBaseDaoFacade dao = new DataBaseDaoFacade();
			dao.add(t);
			Object obj = dao.getByPK("2dd27cfda7cc46e3b8c96c0b06ae269e", Test.class);
			Test tt = (Test) obj;
			System.out.println(tt.getId());
			System.out.println(tt.getName());
			System.out.println(tt.getGuid());
			conn.close();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
